const App = {
    mixins: [Save],//配置文件，路径/utils/mixins.js
    data() {
        return {
            usage: [],
            usageValue: [],
            is:true,
        };
    },
    mounted() {
        let ls_URL = window.location.href;
        let treeNode = getQueryObject(ls_URL, "treeNode");// 获取 nodeKey 参数
        if (treeNode&&this.action=='Add') {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryByTableName`,
                type: "POST",
                data: {
                    Data: 'natural_resources_usage',
                    Condition: "Row_Status = '0'"
                },
                success: (data) => {
                    this.changeUsage([treeNode])
                    let obj = data.filter(i=>i.Natural_Resource_Usage_SerialNumber == treeNode)[0];
                    let obj1 = data.filter(i=>i.Natural_Resource_Usage_SerialNumber == obj.Parent_SerialNumber)[0];
                    let obj2 = data.filter(i=>i.Natural_Resource_Usage_SerialNumber == obj1.Parent_SerialNumber)[0];
                    let obj3 = data.filter(i=>i.Natural_Resource_Usage_SerialNumber == obj2.Parent_SerialNumber)[0];
                    this.usageValue = [obj3.Natural_Resource_Usage_SerialNumber,obj2.Natural_Resource_Usage_SerialNumber,obj1.Natural_Resource_Usage_SerialNumber,treeNode]
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        }
        this.getCategory();
    },
    watch:{
        'dataForm.Parent_SerialNumber'(val){
            if (this.action=='Modify'&&this.is) {
                this.is = false;
                $.ajax({
                    headers: requestHeaders(),
                    url: `${mh}/generalBusiness/generalQueryByTableName`,
                    type: "POST",
                    data: {
                        Data: 'natural_resources_usage',
                        Condition: "Row_Status = '0'"
                    },
                    success: (data) => {
                        let obj = data.filter(i=>i.Natural_Resource_Usage_SerialNumber == val)[0];
                        let obj1 = data.filter(i=>i.Natural_Resource_Usage_SerialNumber == obj.Parent_SerialNumber)[0];
                        let obj2 = data.filter(i=>i.Natural_Resource_Usage_SerialNumber == obj1.Parent_SerialNumber)[0];
                        let obj3 = data.filter(i=>i.Natural_Resource_Usage_SerialNumber == obj2.Parent_SerialNumber)[0];
                        this.usageValue = [obj3.Natural_Resource_Usage_SerialNumber,obj2.Natural_Resource_Usage_SerialNumber,obj1.Natural_Resource_Usage_SerialNumber,val]
                    },
                    complete: (XMLHttpRequest) => {
                        requestPretreatment(XMLHttpRequest);
                    },
                    dataType: "json",
                });
            }
        }
    },
    methods: {
        getCategory() {
            $.ajax({
                headers: requestHeaders(),
                url: `${mh}/generalBusiness/generalQueryForObtainingTrees`,
                type: "GET",
                data: {
                    TableName: 'natural_resources_usage',
                    NodeCode: ''
                },
                success: (data) => {
                    this.usage = data; // 直接使用 this
                },
                complete: (XMLHttpRequest) => {
                    requestPretreatment(XMLHttpRequest);
                },
                dataType: "json",
            });
        },
        changeUsage(row) {
            if (row.length > 0) {
                this.dataForm.Parent_SerialNumber = row[row.length - 1]
            }
        }
    },
};
const { createApp, ref } = Vue;
const app = createApp(App);
app.use(ElementPlus, { locale: zhCn });
//这种方式是引入全部图标，无需单个引入
for (const [key, component] of Object.entries(ElementPlusIconsVue)) {
    app.component(key, component);
}
app.component('yl-upload', ylUpload);
app.component('yl-text-editor', ylTextEditor);
const ElMessage = ElementPlus.ElMessage;
app.mount("#app");
